<template>
  <div class="cashApplyDetails">
    <div class="header-box">
      <div class="title">提现申请详情</div>
      <div class="btns">
        <el-button icon="CircleClose" round @click="doClose">关闭</el-button>
        <el-button v-if="!cashInfo.applyStatus" icon="SuccessFilled" round type="success" @click="doExamine">确认提现</el-button>
      </div>
    </div>
    <div class="content">
      <el-card shadow="never">
        <template #header>
          <el-icon color="#ffffff"><Tickets /></el-icon>
          <span class="title">提现银行卡信息</span>
        </template>
        <template #default>
          <div class="info">
            <div><span>经销商编号：</span><span>{{ cashInfo.dealerCode }}</span></div>
            <div><span>开户行：</span><span>{{ cashInfo.bank }}</span></div>
            <div><span>开户支行：</span><span>{{ cashInfo.branchBank }}</span></div>
            <div><span>银行卡号：</span><span>{{ cashInfo.bankCard }}</span></div>
            <div><span>开户人姓名：</span><span>{{ cashInfo.memberName }}</span></div>
            <div><span>开户人电话：</span><span>{{ cashInfo.phone }}</span></div>
            <div style="color: #F95505;">
              <span>状态：</span>
              <span>{{ cashInfo.applyStatus ? '已提现' : '申请中' }}</span>
            </div>
          </div>
        </template>
      </el-card>
      <el-card shadow="never">
        <template #header>
          <el-icon color="#ffffff"><Document /></el-icon>
          <span class="title">提现金额计算</span>
        </template>
        <template #default>
          <div class="info">
            <div><span>提现积分：</span><span>{{ cashInfo.tradePoint }}</span></div>
            <div>
              <span>提现金额：</span>
              <span>
                <el-input v-model="cashInfo.amount" placeholder="请输入提现金额" clearable style="width: 150px;">
                  <template #prefix>
                    <span>￥</span>
                  </template>
                </el-input>
              </span>
            </div>
            <div><span>提现手续费：</span><span>{{ cashInfo.tradeCharges }}</span></div>
            <div class="remark">
              <span>提现备注：</span>
              <span>
                <el-input v-model="cashInfo.description" :rows="5" type="textarea" placeholder="请输入提现备注" style="width: 400px;"/>
              </span>
            </div>
          </div>
        </template>
      </el-card>
    </div>
  </div>
</template>

<script setup name="cashApplyDetails">
  import { getCashApplyInfoApi, passOrRejectCashApplyApi } from '@/api/api'
  import { ref, getCurrentInstance, watch } from 'vue'

  // 获取注册的全局实列
  const currentThis = getCurrentInstance().appContext.config.globalProperties

  // 定义父组件传入的值
  const props = defineProps({
    cashOutId: {
      type: String,
      default: ''
    }
  })
  // 定义传值给父组件数据方法
  const emits = defineEmits(['close'])

  let cashInfo = ref({
    cashOutId: '',
    dealerCode: '',
    bank: '',
    branchBank: '',
    bankCard: '',
    memberName: '',
    phone: '',
    applyStatus: '',
    tradePoint: '',
    amount: '',
    tradeCharges: '',
    description: ''
  })

  watch(() => props.cashOutId, (newVal) => {
    init()
  }, {
    immediate: true // 立即监听
  })

  function init() {
    getCashApplyInfoApi(props.cashOutId).then(res => {
      if(res.code === '200') {
        cashInfo.value = res.data
      } else {
        currentThis.$message.error(res.message)
      }
    })
  }

  function doExamine() {
    currentThis.$messageBox.confirm('确认提现吗？').then(() => {
      let loading = currentThis.$loading('正在处理，请耐心等待')
      passOrRejectCashApplyApi('pass', {
        cashOutId: cashInfo.value.cashOutId,
        amount: cashInfo.value.amount,
        tradeCharges: cashInfo.value.tradeCharges,
        description: cashInfo.value.description
      }).then(res => {
        loading.close()
        if(res.code === '200') {
          currentThis.$message.success(res.message)
          doClose()
        } else {
          currentThis.$message.error(res.message)
        }
      })
    }).catch(() => {})
  }

  function doClose() {
    emits('close')
  }
</script>

<style lang="less" scoped>
.cashApplyDetails{
  padding: 0 20%;
  .header-box{
    height:8vh;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .title{
      font-size: 25px;
      font-weight: bold;
    }
    .btns{
      display: flex;
      justify-content: flex-end;
    }
  }
  .content{
    height: 92vh;
    overflow: hidden auto;
    :deep(.el-card){
      margin-bottom: 15px;
      .el-card__header{
        display: flex;
        align-items: center;
        background: #3BB9F1;
        .el-icon{
          margin-right: 5px;
        }
        .title{
          color: #ffffff;
        }
      }
      .el-card__body{
        .info{
          display: flex;
          flex-wrap: wrap;
          >div{
            width: 33.3%;
            padding: 10px 0;
            color: #333333;
            font-size: 14px;
            display: flex;
            align-items: center;
          }
          .remark{
            align-items: flex-start;
            width: 50%;
          }
        }
        .el-image{
          width: 60px;
          height: 60px;
          border-radius: 8px;
          margin-right: 5px;
        }
      }
    }
  }
}
</style>